import React from "react";
import { View } from "@tarojs/components";
import "./index.scss";
import { ModalProps } from "../../../types/components/modal";

/**
 * Modal Modal浮窗
 */
const Modal = ({
  title,
  content,
  cancelText = "取消",
  confirmText = "确定",
  success
}: ModalProps) => {
  const onSelect = function(status: boolean) {
    const event = {
      cancel: status,
      confirm: !status
    };
    success && success(event);
  };

  return (
    <View className="modal">
      <View className="core">
        <View className="title">{title}</View>
        <View className="content">{content}</View>
      </View>
      <View className="footer">
        <View onClick={() => onSelect(true)}>{cancelText || "取消"}</View>
        <View onClick={() => onSelect(false)}>{confirmText || "确定"}</View>
      </View>
    </View>
  );
};

export default Modal;
